/**
 * 进入引用，并确保在首页
 */
function returnHome(packageName, text1, text2) {
  launch(packageName);
  sleep(1000);
  var home = text(text1).findOnce();
  var otherIcon = text(text2).findOnce();

  //确保在首页
  while(home == null  && otherIcon == null) {
    back()
    sleep(500)
    home = text(text1).findOnce();
    otherIcon = text(text2).findOnce();
  }
  //点击第一文本图标
  home.parent().parent().click();
  sleep(500);
} 

/**
 * 如果锁屏状态会解锁屏幕
 */
function unlock(password) { 
 const { width, height } = device;
 var pwdArr = password.split('');
 if(!device.isScreenOn()) {
  device.wakeUp();
  sleep(1000);
  swipe(width/2, height/5*3, width/2, height/4*1,500);
  sleep(1000);
   
  for(var i = 0; i < pwdArr.length; i++) {
    click(pwdArr[i]);
  }
   
 } 
}
